#define _CRT_SECURE_NO_WARNINGS 1
#pragma once

#include <string.h>
#include <assert.h>
#include <iostream>
using namespace std;

namespace Mine
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}

		const_iterator end() const
		{
			return _str + _size;
		}

		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}

		string(const char* str = "");
		string(size_t n, char ch);
		string(const string& s);
		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);
		void insert(size_t pos, size_t n, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);
		size_t find(char ch,size_t = 0);
		size_t find(const char* str, size_t = 0);
		string substr(size_t pos ,size_t len);

		char*& c_str()
		{
			return _str;
		}

		size_t size()
		{
			return _size;

		}

		size_t capacity()
		{
			return _capacity;
		}

		string& operator+=(char ch);
		string& operator+=(const char* str);
		string& operator=(string& s);

		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;
		bool operator<(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>(const string& s) const;
		bool operator>=(const string& s) const;
	
		~string();
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		const static size_t npos;
	};

	ostream& operator<<(ostream& out, const string& s);
	istream& operator>>(istream& in, string& s);
	istream& getline(istream& in, string& s, char delim = '\n');
}

void test1();
void test2();
void test3();
void test4();